package cn.easybuy.service.user;

import java.sql.Connection;
import java.sql.SQLException;

import cn.easybuy.dao.user.UserDao;
import cn.easybuy.dao.user.UserDaoImpl;
import cn.easybuy.entity.User;
import cn.easybuy.utils.DataSourceUtil;

public class UserServiceImpl implements UserService {
	
	//根据ID查询用户信息
		public User findByLoginName(String loginName) {
			Connection connection = null;
			User user = null;
			try {
				connection = DataSourceUtil.openConnection();
				UserDao userDao = new UserDaoImpl(connection);
				user = userDao.findByLoginName(loginName);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				DataSourceUtil.closeConnection(connection);
			}
			return user;
		}

		
		public boolean save(User user) {//新增用户信息
			boolean flag=false;
			Connection connection = null;
			try {
				connection = DataSourceUtil.openConnection();
				UserDao userDao = new UserDaoImpl(connection);
				int count=userDao.save(user);
				flag=count>0;
				return flag;
			} catch (Exception e) {
				flag=false;
				e.printStackTrace();
				return flag;
			} finally {
				DataSourceUtil.closeConnection(connection);
				
			}
		}
}
